package cn.kooki.app.duobao.ui.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import cn.kooki.app.duobao.R;
import cn.kooki.app.duobao.data.Bean.User.address.AddressItem;

/**
 * Created by xiong on 2015/12/16.
 */
public class AddressSpinnerAdapter extends BaseAdapter {

    private Context context;
    private ArrayList<AddressItem> addressItems;

    public AddressSpinnerAdapter(Context context, ArrayList<AddressItem> addressItems) {
        this.context = context;
        this.addressItems = addressItems;
    }


    @Override
    public int getCount() {
        return addressItems.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Viewholder viewholder = null;
        AddressItem addressItem = addressItems.get(position);
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.simple_spinner_dropdown_item, parent, false);
            viewholder = new Viewholder();
            viewholder.tv_spineritem = (TextView) convertView.findViewById(R.id.tv_spinner_address);
            convertView.setTag(viewholder);
        } else {
            viewholder = (Viewholder) convertView.getTag();
        }
        viewholder.tv_spineritem.setText(addressItem.getName());

        return convertView;
    }

    static class Viewholder {
        TextView tv_spineritem;
    }
}
